#include<stdio.h>
#include<string.h>
int main()
{
    //fwrite;
    FILE* fp = fopen("bite.txt","w");
    if(fp==NULL)
    {
        printf("fopen fail\n");
        return -1;
    }
    const char* str="linux so easy!\n";
    fwrite(str,sizeof(str[0]),strlen(str),fp);
    fclose(fp);

    //fread
    FILE* fp2 = fopen("bite.txt","r");
    if(fp2==NULL)
    {
        printf("fopen fail\n");
        return 1;
    }
    char ch;
    while(fread(&ch,sizeof(char),1,fp2)==1)
    {
        printf("%c",ch);
    }
    fclose(fp2);

    //fseek
    FILE* fp3 = fopen("bite.txt","r");
    if(fp3==NULL)
    {
        printf("fopen fail");
        return 3;
    }
    char val;
    fseek(fp3,-2,SEEK_END);
    val=fgetc(fp3);
    printf("%c ",val);

    fseek(fp3,1,SEEK_SET);
    val=fgetc(fp3);
    printf("%c ",val);

    fseek(fp3,0,SEEK_CUR);
    val=fgetc(fp3);
    printf("%c \n",val);
    return 0;
}
